﻿using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

namespace VIP.Extension
{

    public static class VIPIOExtension
    {

        /// <summary>
        /// 创建新的文件夹,如果存在则不创建
        /// </summary>
        /// <param name="dirFullPath">文件全路径</param>
        /// <returns></returns>
        public static string CreateDirIfNotExists(this string dirFullPath)
        {
            if (!Directory.Exists(dirFullPath))
            {
                Directory.CreateDirectory(dirFullPath);
            }

            return dirFullPath;
        }

        /// <summary>
        /// 删除文件夹，如果存在
        /// </summary>
        /// <param name="dirFullPath">文件全路径</param>
        public static void DeleteDirIfExists(this string dirFullPath)
        {
            if (Directory.Exists(dirFullPath))
            {
                Directory.Delete(dirFullPath, true);
            }
        }

        /// <summary>
        /// 清空文件夹,如果存在。
        /// </summary>
        /// <param name="dirFullPath">文件全路径</param>
        public static void ClearDirIfExists(this string dirFullPath)
        {
            if (Directory.Exists(dirFullPath))
            {
                Directory.Delete(dirFullPath, true);
            }
            Directory.CreateDirectory(dirFullPath);
        }

        /// <summary>
        /// 删除文件 如果存在
        /// </summary>
        /// <param name="fileFullPath">文件全路径</param>
        /// <returns> True if exists</returns>
        public static bool DeleteFileIfExists(this string fileFullPath)
        {
            if (File.Exists(fileFullPath))
            {
                File.Delete(fileFullPath);
                return true;
            }

            return false;
        }

    }

}